package direct;

import com.rabbitmq.client.*;
import utils.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author xj
 * @create 2021/8/13 0:13
 */
public class CustomerError {

    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = ConnectionUtils.getConnection("localhost", 5672, "/xj", "xj", "123");
        Channel channel = connection.createChannel();
        /*声明生产者创建的交换机*/
        channel.exchangeDeclare("directName", "direct");
        /*创建临时队列*/
        String queue = channel.queueDeclare().getQueue();
        /*绑定队列和交换机*/
        channel.queueBind(queue, "directName", "error");
        channel.queueBind(queue, "directName", "info");

        channel.basicConsume(queue, true, new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者error = " + new String(body));
            }
        });
    }
}
